home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / src / interp / tclStruct1.2.tar.gz / tclStruct1.2.tar / tclStruct1.2 / stDebug.c < prev    next >
C/C++ Source or Header  |  1995-09-12  |  2KB  |  95 lines

  1. /*
  2.  *    tclStruct package
  3.  *  Support 'C' structures in Tcl
  4.  *
  5.  *  Written by Matthew Costello
  6.  *  (c) 1995 AT&T Global Information Solutions, Dayton Ohio USA
  7.  *
  8.  *  See the file "license.terms" for information on usage and
  9.  *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  10.  */
  11. #include "stInternal.h"
  12. STRUCT_SCCSID("@(#)tclStruct:stDebug.c    1.1    95/09/08")
  13.  
  14. #ifdef DEBUG
  15. /*  When DEBUG is defined, enable the display of debugging messages.
  16.  */
  17. int    struct_debug = DEBUG;
  18. static struct {
  19.     const char *name;
  20.     int value;
  21. } debug_names[] = {
  22.     { "refcount",    DBG_REFCOUNT },
  23.     { "newtype",    DBG_NEWTYPE },
  24.     { "parsetype",    DBG_PARSETYPE },
  25.     { "parseelement",    DBG_PARSEELEMENT },
  26.     { "lookup",    DBG_LOOKUP },
  27.     { "newobject",    DBG_NEWOBJECT },
  28.     { "getobject",    DBG_GETOBJECT },
  29.     { "float",    DBG_FLOAT },
  30.     { "int",    DBG_INT },
  31.     { "char",    DBG_CHAR },
  32.     { "array",    DBG_ARRAY },
  33.     { "unset",    DBG_UNSET },
  34.     { "command",    DBG_COMMAND },
  35.     { "varlen",    DBG_VARLEN },
  36.     { "io",        DBG_IO },
  37.     { "all",    ~0 },
  38.     { "none",    0 },
  39.     { NULL, 0 }
  40. };
  41.  
  42. void
  43. Struct_PrintCommand(argc,argv)
  44.   int argc;
  45.   char **argv;
  46. {
  47.     int i;
  48.     printf("COMMAND:");
  49.     for ( i = 0; i < argc; i++ )
  50.     printf(" %s", argv[i] );
  51.     printf("\n");
  52. }
  53.  
  54. /*ARGSUSED*/
  55. int
  56. Struct_DebugInfo(cdata,interp,argc,argv)
  57.   ClientData cdata;
  58.   Tcl_Interp *interp;
  59.   int argc;
  60.   char **argv;
  61. {
  62.     int i, l, n;
  63.     if (argc < 3) {
  64.     Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
  65.         " debug +/-debugFlagName\"", (char *) NULL);
  66.     return TCL_ERROR;
  67.     }
  68.     for ( i = 2; i < argc; i++ ) {
  69.     if (*argv[i] != '+' && *argv[i] != '-') {
  70.         Tcl_AppendResult(interp,
  71.             "debug flags must be preceeded by '+' or '-'", NULL );
  72.         return TCL_ERROR;
  73.     }
  74.     l = strlen( argv[i]+1 );
  75.     for ( n = 0; debug_names[n].name ; n++ ) {
  76.         if (strncmp( debug_names[n].name, argv[i]+1, l ) == 0) {
  77.         break;
  78.         }
  79.     }
  80.     if (!debug_names[n].name) {
  81.         Tcl_AppendResult(interp,
  82.             "debug flag \"", argv[i]+1, "\" does not exist", NULL );
  83.         return TCL_ERROR;
  84.     } else if (*argv[i] == '-') {
  85.         struct_debug &= ~debug_names[n].value;
  86.     } else {
  87.         struct_debug |= debug_names[n].value;
  88.     }
  89.     }
  90.     Tcl_ResetResult(interp);
  91.     sprintf(interp->result,"%u",struct_debug);
  92.     return TCL_OK;
  93. }
  94. #endif
  95.